﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class EditRoomCategory
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack = True Then
                fillData(Request.QueryString("Id"))
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub fillData(ByVal Id As Integer)
        Dim txt As Array
        txt = RetriveData("SELECT [Id],[Name], [IsActive] FROM [ptn_RoomCategory] where Id=" & Id, 2)
        txtName.Text = Server.HtmlDecode(txt(1))
        chkActive.Checked = txt(2)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim strActive As String
            If chkActive.Checked = True Then
                strActive = 1
            Else
                strActive = 0
            End If
            If Request.QueryString("Id") Is Nothing Then
                Dim arr As Array
                arr = RetriveData("Select Id from ptn_RoomCategory where Name='" & Server.HtmlEncode(Trim(txtName.Text.Replace("'", "&#039;"))) & "'", 0)
                If arr(0) Is Nothing Then
                    Insert_Update_Delete_Record("Insert into ptn_RoomCategory (Name, IsActive) values('" & Server.HtmlEncode(txtName.Text.Replace("'", "&#039;")) & "'," & strActive & ")")
                    Response.Redirect("ViewRoomCategory.aspx")
                Else
                    lblMsg.Text = "Room Category already exist."
                End If
            Else
                Insert_Update_Delete_Record("Update ptn_RoomCategory set Name='" & Server.HtmlEncode(txtName.Text.Replace("'", "&#039;")) & "',IsActive=" & strActive & " where Id=" & Request.QueryString("Id"))
                Response.Redirect("ViewRoomCategory.aspx")
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("ViewRoomCategory.aspx")
    End Sub
End Class